//=============================================================================
// XBus 
//-----------------------------------------------------------------------------
// File        : xbus_cell.c
// Description : 
// Author      : Ismail Sabry
// Date        : 1/30/2009
//=============================================================================
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <xbus.h>

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
int XBUS_init_module(t_XBUS_module *module)
{
  module->head.magictag = XBUS_MAGICTAG_MODULE;
  module->head.witer    = 0;
  module->head.wcell    = 0;
  
  return(0);
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
t_XBUS_module *XBUS_get_module_by_index(t_XBUS *xbus, unsigned int imodule)

{
  unsigned int     offset, sz_module, sz_cell;
  t_XBUS_module    *module;
  
  if(imodule >= xbus->head.nb_module) {
    printf("XBus bad module index (%u, max %d)\n", imodule, xbus->head.nb_module);
    return((t_XBUS_module *)-1);
  } 

  sz_cell   = sizeof(t_XBUS_cell_header)   + (xbus->head.size_cell);
  sz_module = sizeof(t_XBUS_module_header) + (xbus->head.nb_cell   *   sz_cell);
  
  offset    = sizeof(t_XBUS_header) + (imodule * sz_module);
  
  module = (t_XBUS_module *)((unsigned char *)xbus + offset);
    
  //printf("module(%u) %p - xbus %p / offset %u \n", imodule, module, xbus, offset);
  
  return(module);
}


//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
int XBUS_lock(t_XBUS_module *module, unsigned int timeout)
{
  return(0);
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
int XBUS_unlock(t_XBUS_module *module)
{
  return(0);
}
